package com.jinlia.show.modules.base.wxapp.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinlia.show.modules.base.wxapp.entity.SignLog;
import com.jinlia.show.modules.base.wxapp.mapper.SignLogMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class SignLogMapperService  extends ServiceImpl<SignLogMapper, SignLog> {
    public SignLog add(SignLog signLog) {
        SignLog one = this.lambdaQuery()
                .eq(SignLog::getUserId, signLog.getUserId())
                .eq(SignLog::getSignDate, LocalDate.now())
                .one();
        if (one != null) {
            return one;
        }
        signLog.setSignTime(LocalDateTime.now());
        signLog.setSignDate(LocalDate.now());
        this.save(signLog);
        return signLog;
    }

    public List<SignLog> getList(SignLog signLog) {
        List<SignLog> list = this.lambdaQuery()
                .eq(SignLog::getUserId, signLog.getUserId())
                .list();
        return list;
    }
}
